package com.leyou;

import com.leyou.common.vo.PageResult;
import com.leyou.dto.SpecParamDTO;
import com.leyou.dto.SpuDTO;
import com.leyou.item.client.ItemClient;
import com.leyou.search.domain.Goods;
import com.leyou.search.mapper.GoodsRepository;
import com.leyou.search.service.SearchService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class insertIndex {
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private SearchService searchService;
    @Autowired
    private GoodsRepository goodsRepository;

    @Test
    public void test(){
        Integer page = 1 ;
        Integer rows = 100 ;
        Integer totalPage = 1;

        do{
            PageResult<SpuDTO> pageResult = itemClient.querySpuByPage(page, rows, null, true);
            //当前页的集合
            List<SpuDTO> items = pageResult.getItems();
            for (SpuDTO item : items) {
                Goods good = searchService.invertGoods(item);
                goodsRepository.save(good);
            }
            totalPage = pageResult.getTotalPage();
            page++;
        }while (page<=totalPage);


    }

    @Test
    public void test02(){
        PageResult<SpuDTO> spuDTOPageResult = itemClient.querySpuByPage(1, 100, null, true);
        System.out.println(spuDTOPageResult.getItems());
        System.out.println(spuDTOPageResult.getTotal());
        System.out.println(spuDTOPageResult.getTotalPage());
        System.out.println("======================================");
        System.out.println(itemClient.findSpuDetailById(2L));
        System.out.println("======================================");
        System.out.println(itemClient.findSkuById(3L));
        System.out.println("======================================");
        List<SpecParamDTO> list = itemClient.querySpecParams(null, 76L, null);
        System.out.println(list.size());
    }

}
